<?php
/*
Plugin Name: WordPress Vampire Word Spinner
Plugin URI: http://www.wpvampire.com
Description: Better Word Spinner Plugin
Author: WordPress Vampire
Version: 1.0
Author URI: http://www.wpvampire.com

*/

// Stop direct call
if (preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
    die('You are not allowed to call this page directly (wvcf).');
}

if (!class_exists('wvLoader')) {
    class wvLoader {

        var $minimum_WP = '2.8';
        var $options = '';
		var $possible_texts = 1;

        function wvLoader() {
            // Stop the plugin if we missed the requirements
            if (!$this->required_version()) return;

            // Register_taxonomy must be used during the init and before loading any dependencies
//            add_action('init', array(&$this, 'register_custom_taxonomy'));
            add_action('init', array(&$this, 'load_dependencies'));

            // Get some constants first
            $this->define_constant();
            $this->define_tables();
            $this->plugin_name = plugin_basename(__FILE__);

            // Init options & tables during activation & deregister init option
            register_activation_hook($this->plugin_name, array(&$this, 'activate'));
            register_deactivation_hook($this->plugin_name, array(&$this, 'deactivate'));

            // Register a uninstall hook to remove all tables & option automatic
            register_uninstall_hook($this->plugin_name, array(&$this, 'uninstall'));
        }

        function register_custom_taxonomy() {

        }

        function required_version() {
            global $wp_version;

            // Check for WP version installation
            $wp_ok = version_compare($wp_version, $this->minimum_WP, '>=');
            if (($wp_ok == FALSE)) {
                add_action('admin_notices', create_function('', 'global $wv; printf (\'<div id="message" class="error"><p><strong>\' . __(\'Sorry, WordPress Vampire Word Spinner plugin works only under WordPress %s or higher\', "wv" ) . \'</strong></p></div>\', $wv->minimum_WP );'));
                return false;
            }

            return true;
        }

        function render($template, $data = array(), $admin = true) {

            extract($data);

            if (!$template) {
                return false;
            }
            if (!$admin) {
                include_once (dirname(__FILE__) . '/views/' . $template . '.php');
            } else {
                include_once (dirname(__FILE__) . '/admin/views/' . $template . '.php');
            }
        }

        function define_constant() {
            define('WVVERSION', $this->version);

            // define URL
            define('WVFOLDER', plugin_basename(dirname(__FILE__)));

            define('WV_ABSPATH', trailingslashit(str_replace("\\", "/", WP_PLUGIN_DIR . '/' . plugin_basename(dirname(__FILE__)))));
            define('WV_URLPATH', trailingslashit(WP_PLUGIN_URL . '/' . plugin_basename(dirname(__FILE__))));
        }

        function define_tables() {
            global $wpdb;
        }

        function load_dependencies() {
            // Load global libraries
//            require_once (dirname(__FILE__) . '/lib/wvdb.php');
                // Load backend libraries
            if (is_admin()) {
                require_once (dirname(__FILE__) . '/admin/admin.php');
                require_once (dirname(__FILE__) . '/admin/functions.php');
                require_once (dirname(__FILE__) . '/admin/install.php');
                new WV_AdminPanel();
            } else {
                wp_enqueue_script('jquery');
                require_once (dirname(__FILE__) . '/functions.php');
            }
        }

        function activate() {
            flush_rewrite_rules();

            add_option('wspin_splitchar', ";");
            add_option('wspin_leftchar', "{");
            add_option('wspin_rightchar', "}");
        }

        function deactivate() {
            flush_rewrite_rules();
        }

        function install() {
            // wv_install();
        }

        function uninstall() {
            // wv_uninstall();
        }

    }

    // Start the holy plugin
    global $wv;
    $wv = new wvLoader();
}